#include "debug.h"
#include "Utils\\Color.h"

NS_BEGIN(SDL)
NS_BEGIN(UTILS)

#pragma region CTOR & DTOR

Color::Color(Uint8 _r, Uint8 _g, Uint8 _b)
{
	CTOR("Color", this);
	m_color.r = _r;
	m_color.g = _g;
	m_color.b = _b;
}

Color::Color(SDL_Color const& _color)
	: m_color(_color)
{
	CTOR("Color", this);
}

Color::Color(Uint32 _color)
{
	m_color.r = _color >> 16 & 0xFF;
	m_color.g = _color >> 8 & 0xFF;
	m_color.b = _color & 0xFF;
}

Color::Color(Color const& _color)
{
	CTOR("Color", this);
	*this = _color;
}

Color::~Color()
{
	DTOR("Color", this);
}

#pragma endregion
#pragma region Operators

Color& Color::operator=(Color const& _color)
{
	if (this != &_color)
	{
		m_color = _color.m_color;
	}
	return (*this);
}

bool Color::operator==(Color const& _color) const
{
	return (m_color.r == _color.GetR() && m_color.g == _color.GetG() &&
			m_color.b == _color.GetB());
}

bool Color::operator!=(Color const& _color) const
{
	return (m_color.r != _color.GetR() || m_color.g != _color.GetG() ||
			m_color.b != _color.GetB());
}

#pragma endregion

void Color::InitSDLColor(SDL_Color& _color, Uint8 _r, Uint8 _g, Uint8 _b)
{
	_color.r = _r;
	_color.g = _g;
	_color.b = _b;
}

void Color::ToSDLColor(SDL_Color& _color) const
{
	_color = m_color;
}

Uint32 Color::ToUint32() const
{
	Uint32 result = 0;

	result += m_color.r << 16 & 0x00FF0000;
	result += m_color.g <<  8 & 0x0000FF00;
	result += m_color.b <<  0 & 0x000000FF;

	return (result);
}

#pragma region Getters & Setters

SDL_Color const& Color::GetColor() const
{
	return (m_color);
}

void Color::SetColor(SDL_Color const& _color)
{
	m_color = _color;
}

Uint8 Color::GetR() const
{
	return (m_color.r);
}

void Color::SetR(Uint8 _r)
{
	m_color.r = _r;
}

Uint8 Color::GetG() const
{
	return (m_color.g);
}

void Color::SetG(Uint8 _g)
{
	m_color.g = _g;
}

Uint8 Color::GetB() const
{
	return (m_color.b);
}

void Color::SetB(Uint8 _b)
{
	m_color.b = _b;
}

#pragma endregion

NS_END(UTILS)
NS_END(SDL)
